-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Introduce new graph API in beta #2982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Docs Preview
|
f410d5c to
17555b4
Compare
|
Thank you @dmontagu for your work on this. I've tried the beta graph API and I really like it. |
2 tasks
Collaborator
Author
|
@sirianni David put some notes on persistence with the new API in #530 (comment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new Beta Graph API for
pydantic-graphthat provides enhanced capabilities for parallel execution, conditional branching, and complex workflows. The original graph API remains fully supported and is compatible with the new beta API.Key Features
Builder Pattern Interface
The new API uses a function-based builder pattern with the
@g.stepdecorator instead of the class-basedBaseNodeapproach. This makes it much easier to dynamically define connections between nodes:Steps accept a
StepContextargument that is generic in input type, output type, and state type. A state instance is shared across the run similar to how graphs currently work, but steps now also have inputs that come from the immediately preceding step, and outputs that go to the immediately following step. This allows you to design your graph for better type-safety than you typically get when using a global state object that is built incrementally during the course of a graph run. (And you always have the option to leave the inputs/outputs asNoneand stick with just using/modifying thestateduring the run.)More generally, we have thorough type-checking for all edges —
Parallel Execution Operations
g.map()) - Fan out to process iterables in parallelg.broadcast()) - Send the same data to multiple parallel pathsConditional Branching
Advanced Execution Control
graph.iter()for fine-grained control (just like in the previous, non-beta API), even during parallel execution.Closes #704